﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace Gauss.Isp.Attributes
{
    /// <summary>
    /// This is an extension of the CategoryAttribute class, supporting
    /// localized category strings.
    /// </summary>
    public sealed class LocalizedCategoryAttribute : CategoryAttribute
    {
        /// <summary>
        /// This is the current resource manager which is used to convert the
        /// category resource ID to the localized version.
        /// </summary>
        private static global::System.Resources.ResourceManager _resourceManager;
        
        /// <summary>
        /// This is the resource ID to use, to convert the category name to the
        /// localized string.
        /// </summary>
        private string _categoryString;

        /// <summary>
        /// This returns the resource manager used to get the localized string,
        /// and it caches the value in _resourceManager.
        /// </summary>
        internal static global::System.Resources.ResourceManager ResourceManager
        {
            get
            {
                if (_resourceManager == null)
                {
                    _resourceManager = new global::System.Resources.ResourceManager("Gauss.Isp.Resources", typeof(Resources).Assembly);
                }
                return _resourceManager;
            }
        }

        /// <summary>
        /// This creates a category by converting the categoryId to the correct
        /// localized string.
        /// </summary>
        /// <param name="categoryId">The resource ID of the category in the resources file.</param>
        public LocalizedCategoryAttribute(string category) : base(category)
        {
            this._categoryString = category;
        }

        /// <summary>
        /// Returns the localized string for the category.
        /// </summary>
        /// <param name="value">The category ID.</param>
        /// <returns>The localized string for the category ID.</returns>
        protected override string GetLocalizedString(string value)
        {
            return ResourceManager.GetString(value);
        }

    }
}
